<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>登录</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.11/vue.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.js"></script>
  <script src="/js/md5.min.js"></script>
  <script src="/js/common.js"></script>
</head>
<body>
<div id="root">
  <form v-on:submit.prevent="login">
    <h3>用户登录</h3>
    <div>
      <input type="text" placeholder="手机号码" required v-model.trim="mobile">
    </div>
    <div>
      <input type="password" placeholder="密码" required v-model.trim="password">
    </div>
    <div>
      <button type="reset">重置</button>
      <button type="submit">登录</button>
    </div>
  </form>
</div>

<script>
  const vm = new Vue({
    el: "#root",
    data: {
      mobile: null,
      password: null,
    },
    methods: {
      login() {
        axios.post("/login", {
          mobile: this.mobile,
          password: g_mix_password(this.password)
        }).then(resp => {
          const remoteRedirect = resp.headers["s_redirect_uri"];
          const localRedirect = g_getRedirectAndClear();
          window.location.href = remoteRedirect || localRedirect || "/goods.html";
        }).catch(error => {
          console.log({error});
          alert(error.response.data);
        });
      }
    }
  });
</script>
</body>
</html>
